<!--
  -    Copyright (c) 2018-2025, lengleng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
	<div class="execution">
		<basic-container>
			<avue-form
				ref="form"
				v-loading="loading"
				v-model="fd"
				:option="option"
				@reset-change="resetForm"
				@submit="submitForm"
				:upload-error="uploadError"
			>
			</avue-form>
		</basic-container>
	</div>
</template>

<script>
import {
	fetchList,
	getObj,
	addObj,
	putObj,
	delObj
} from "@/api/circlecommerce";
import {tableOption} from "@/const/crud/circlecommerce";
import {mapGetters} from "vuex";
import AvueUeditor from 'avue-plugin-ueditor'

export default {
	name: "circlecommerce",
	data() {
		return {
			loading: true,   //加载中
			fd: {},         //表单数据
		};
	},
	computed: {
		option() {
			return {
				size: this.sizeValue,
				mockBtn: false,
				submitText: "保存",
				printBtn: false,
				labelWidth:150,
				column: [
					{
						label: "公司名称",
						prop: "name",
						span: 22,
						maxlength: 30,
						minlength: 2,
						rules: [
							{
								required: true,
								message: "请输入公司名称",
								trigger: "blur"
							}
						],
						change: ({value, column}) => {
						},
						click: ({value, column}) => {
						}
					},
					{
						span: 22,
						type: "upload",
						label: "公司封面",
						prop: "logo",
						hide: true,
						imgWidth: 80,
						listType: "picture-img",
						accept: ["image/png", "image/jpeg"],
						action: "/fastfile/upload/hsh-1251035051",
						multiple: false,
						fileSize: 500000,
						dataType: "string",
						propsHttp: {
							res: "data",
							url: "kpath"
						},
						showFileList: true,
						rules: [
							{
								required: true,
								message: "请上传公司banner",
								trigger: "blur"
							}
						],
						tip: "只能上传jpg/png文件，且不超过500kb,推荐尺寸为:750*324"
					},
					{
						label: "公司领导",
						prop: "leader",
						type: "dynamic",
						span: 22,
						/*  rules: [
						   {
							 required: true,
							 message: "请填写公司领导信息",
							 trigger: "blur"
						   }
						 ], */
						children: {
							align: "center",
							headerAlign: "center",
							rowAdd: done => {
								// this.$message.success("新增回调");
								done({
									sort: 1
								});
							},
							rowDel: (row, done) => {
								// this.$message.success("删除回调" + JSON.stringify(row));
								done();
							},
							column: [
								{
									label: "职位",
									prop: "position",
									/* rules: [
									  {
										required: true,
										message: "请输入职位"
									  }
									] */
								},
								{
									label: "姓名",
									prop: "fullname",
									type: "input",
									placeholder: '请输入姓名（多个姓名用“,”分割）',
									/* rules: [
									  {
										required: true,
										message: "请输入姓名（多个姓名用“,”分割）"
									  }
									] */
								},
								{
									label: "排序",
									prop: "sort",
									type: "number",
									placeholder: '请输入排序号（越小越靠前）',
									/* rules: [
									  {
										required: true,
										message: "请输入排序号（越小越靠前）"
									  }
									] */
								}
							],
						}
					},
					{
						label: "公司简介",
						prop: "introduction",
						type: "textarea",
						span: 22,
						rules: [
							{
								required: true,
								message: "请填写公司简介",
								trigger: "blur"
							}
						]
					},
					{
						span: 22,
						type: "input",
						label: "公司章程",
						prop: "association",
						"component": "AvueUeditor",
						hide: true,
						// upload: {
						//   //普通图片上传
						//   action: "/fastfile/upload/hsh-1251035051",
						//   // fileSize: 500000,
						//   props: {
						//     res: "data",
						//     url: 'kpath'
						//   }
						// },
						params: {
							options: {
								//普通图片上传
								action: "/fastfile/upload/hsh-1251035051",
								customConfig: {},//wangEditor编辑的配置
								fileSize: 500000,
								props: {
									res: "data",
									url: 'kpath'
								}
							},
						},
					},
					{
						span: 22,
						type: "upload",
						label: "小程序LOGO",
						prop: "miniLogo",
						listType: "picture-img",
						accept: ["image/png", "image/jpeg"],
						action: "/fastfile/upload/hsh-1251035051",
						multiple: false,
						fileSize: 500000,
						dataType: "string",
						propsHttp: {
							res: "data",
							url: "kpath"
						},
						showFileList: true,
						rules: [
							{
								required: true,
								message: "请上传小程序LOGO",
								trigger: "blur"
							}
						],
						tip: "只能上传jpg/png文件，且不超过500kb,推荐尺寸为:200*200"
					},
					{
						span: 22,
						type: "upload",
						label: "小程序Banner",
						prop: "banner",
						listType: "picture-img",
						accept: ["image/png", "image/jpeg"],
						action: "/fastfile/upload/hsh-1251035051",
						multiple: false,
						fileSize: 500000,
						dataType: "string",
						propsHttp: {
							res: "data",
							url: "kpath"
						},
						showFileList: true,
						tip: "只能上传jpg/png文件，且不超过500kb,推荐尺寸为:690*300"
					}
				]
			};
		}
	},
	mounted() {
		this.getFormInfo();
	},
	methods: {
		//获取平台信息详情
		getFormInfo() {
			var vm = this;
			getObj(1).then(res => {
				var info = res.data.data;
				if (info != null) {
					if (info.leader) {
						info.leader = JSON.parse(info.leader);
					}
					vm.fd = info;
				}
				vm.loading = false;

			})
		},

		//表单提交
		submitForm(form, done) {
			this.$refs.form.validate((vaild) => {
				if (vaild) {
					var fd = JSON.parse(JSON.stringify(this.fd));
					fd.leader = JSON.stringify(fd.leader);
					putObj(fd).then(res => {
						this.$message.success("保存成功");
						done()

					})
				}
			})
		},

		//表单重置
		resetForm() {
			this.$refs.form.resetForm();
		},

		uploadError(error, column) {
			this.$message.error('上传失败,请检查图片大小是否小于500kb或者网络问题')
			console.log(error, column)
		},
	}
};
</script>
